package com.sgb.goods.view.adapter.inquiry;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.inquiry.PriceCheckListEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;
import com.sgb.goods.view.activity.inquiry.MyInquiryActivity;


/**
 * 描述：个人中心-我的询价--列表适配器
 *
 * @author qiangHeNooo
 * <p>
 * 时间：2021.10.28
 */
public class MyInquiryAdapter extends BaseCommonAdapter<PriceCheckListEntity> {

    private OnItemChildClickListener listener;

    public MyInquiryAdapter() {
        super(R.layout.goods_item_price_check, BR.viewModel);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, PriceCheckListEntity entity) {
        ImageView priceCheckStatus = baseHolder.itemView.findViewById(R.id.goods_price_check_status);
        if (TextUtils.equals(entity.status, String.valueOf(MyInquiryActivity.TAB_QUOTED))) {
            priceCheckStatus.setImageResource(R.mipmap.goods_icon_quoted);
        } else if (TextUtils.equals(entity.status, String.valueOf(MyInquiryActivity.TAB_WAITING))) {
            priceCheckStatus.setImageResource(R.mipmap.goods_icon_waiting_quot);
        } else if (TextUtils.equals(entity.status, String.valueOf(MyInquiryActivity.TAB_EXPIRED))) {
            priceCheckStatus.setImageResource(R.mipmap.goods_icon_expired);
        }

        TextView goodUrgentNeed = baseHolder.itemView.findViewById(R.id.goods_urgent_need);
        if (entity.urgentNeed && !TextUtils.equals(entity.status, String.valueOf(MyInquiryActivity.TAB_EXPIRED))) {
            goodUrgentNeed.setVisibility(View.VISIBLE);
        } else {
            goodUrgentNeed.setVisibility(View.GONE);
        }

        baseHolder.getView(R.id.item_container).setOnClickListener(v -> {
            if (listener != null) {
                listener.onItemChildClick(v, entity, baseHolder.getLayoutPosition());
            }
        });
    }

    /**
     * 设置监听器
     */
    public void setOnItemClickListener(OnItemChildClickListener listener) {
        this.listener = listener;
    }

    /**
     * item的点击监听器
     */
    public interface OnItemChildClickListener {

        /**
         * 点击item
         */
        void onItemChildClick(View view, PriceCheckListEntity entity, int position);
    }

}
